/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ebasclient.gui.bank;

import ebasclient.abstracts.guielements.ViewModeColor;
import ebasclient.gui.bank.item.BankItem;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.text.JTextComponent;
import org.coraci.bas.ws.Bank;
import org.coraci.bas.ws.BankEWS_Service;

/**
 *
 * @author Luca
 */
public class BankMainPanel extends javax.swing.JPanel {

    private List<JComponent> fields = new ArrayList<JComponent>();

    /**
     * Creates new form BankMainPanel
     */
    public BankMainPanel() {
        initComponents();
        for (Bank B : loadBank()) {
            System.out.println("adding item: " + B.toString());
            this.bankTableModel1.addRowElement(new BankItem(B));
        }
        fields.add(this.jTextField_Denominazione);
        fields.add(this.jTextField_SLegale_Indirizzo);
        fields.add(this.jTextField_SLegaleCAP);
        fields.add(this.jTextField_SLegaleCity);
        fields.add(this.jTextField_ABI);
        fields.add(this.jTextField_CodiceFiscale);
        fields.add(this.jTextField_NrAlbo);
        fields.add(this.jTextField_PartitaIVA);
        fields.add(this.jTextField_RegistroImprese);
        fields.add(this.jTextField_SGeneraleCAP);
        fields.add(this.jTextField_SGeneraleCity);
        fields.add(this.jTextField_SGenerale_Indirizzo);
        fields.add(this.jTextField_GruppoBanca);
        fields.add(this.jTextField_CapitaleSociale);
        
        cancel();
        setFormEnabled(false);
    }

    private void setFormEnabled(boolean enabled) {

        for (JComponent field : fields) {
            field.setEnabled(enabled);
        }
        this.jCheckBox1.setEnabled(enabled);

    }

    private void clearForm() {
        for (JComponent field : fields) {
            if (field instanceof JTextComponent) {
                ((JTextComponent) field).setText("");
            }
        }
        this.jCheckBox1.setSelected(false);
    }

    public final List<Bank> loadBank() {
        BankEWS_Service service = new BankEWS_Service();
        return service.getBankEWSPort().findAll();
    }

    public final void visualizeData(Bank bank) {
        jTextField_Denominazione.setText(bank.getDenominazione());
        jTextField_SLegale_Indirizzo.setText(bank.getSedeLegaleIndirizzo());
        jTextField_SLegaleCAP.setText(bank.getSedeLegaleCAP());
        jTextField_SLegaleCity.setText(bank.getSedeLegaleCity());
        jTextField_ABI.setText(bank.getABI());
        jTextField_CodiceFiscale.setText(bank.getCF());
        jTextField_NrAlbo.setText(bank.getNumeroAlbo());
        jTextField_PartitaIVA.setText(bank.getPartitaIVA());
        jTextField_RegistroImprese.setText(bank.getRegistroImprese());
        jTextField_SGeneraleCAP.setText(bank.getSedeGeneraleCAP());
        jTextField_SGeneraleCity.setText(bank.getSedeGeneraleCity());
        jTextField_SGenerale_Indirizzo.setText(bank.getSedeGeneraleCity());
        jTextField_GruppoBanca.setText(bank.getGruppoBancario());
        jTextField_CapitaleSociale.setText(bank.getSedeLegaleCAP());
    }

    public final void cancel() {
        clearForm();
        setFormEnabled(false);
        this.jLabel_Message.setText("");
        this.jLabel_Message.setBackground(null);
        this.jToggleButton_Modify.setEnabled(true);
        this.jToggleButton_Modify.setSelected(false);
        this.jToggleButton_NuovaBanca.setEnabled(true);
        this.jToggleButton_NuovaBanca.setSelected(false);
        this.jButton_Delete.setEnabled(true);
        this.jButton_Salva.setEnabled(false);
        this.jButton_Annulla.setEnabled(false);
//        int limit = jTable1.getRowCount() == 0 ? -1 : jTable1.getRowCount() -1;
//        System.out.println("limit = "+limit);
        if(jTable1.getRowCount() != 0){
            this.jTable1.removeRowSelectionInterval(0, jTable1.getRowCount() -1);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        bankTableModel1 = new ebasclient.gui.bank.item.BankTableModel();
        bankTableRenderer1 = new ebasclient.gui.bank.item.BankTableRenderer();
        jToolBar1 = new javax.swing.JToolBar();
        jToggleButton_NuovaBanca = new javax.swing.JToggleButton();
        jToggleButton_Modify = new javax.swing.JToggleButton();
        jButton_Delete = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jLabel_Message = new javax.swing.JLabel();
        jButton_Salva = new javax.swing.JButton();
        jButton_Annulla = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jTextField_CapitaleSociale = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jTextField_SGeneraleCAP = new javax.swing.JTextField();
        jTextField_SLegaleCAP = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jTextField_SLegale_Indirizzo = new javax.swing.JTextField();
        jTextField_SGenerale_Indirizzo = new javax.swing.JTextField();
        jTextField_GruppoBanca = new javax.swing.JTextField();
        jTextField_ABI = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jCheckBox1 = new javax.swing.JCheckBox();
        jTextField_SLegaleCity = new javax.swing.JTextField();
        jTextField_PartitaIVA = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jTextField_SGeneraleCity = new javax.swing.JTextField();
        jTextField_CodiceFiscale = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();
        jLabel8 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jTextField_NrAlbo = new javax.swing.JTextField();
        jTextField_Denominazione = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jTextField_RegistroImprese = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jDateChooser1 = new com.toedter.calendar.JDateChooser();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jDateChooser2 = new com.toedter.calendar.JDateChooser();

        bankTableRenderer1.setText("bankTableRenderer1");

        jToolBar1.setRollover(true);

        jToggleButton_NuovaBanca.setText("Nuova Banca");
        jToggleButton_NuovaBanca.setFocusable(false);
        jToggleButton_NuovaBanca.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jToggleButton_NuovaBanca.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToggleButton_NuovaBanca.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton_NuovaBancaActionPerformed(evt);
            }
        });
        jToolBar1.add(jToggleButton_NuovaBanca);

        jToggleButton_Modify.setText("Modifica");
        jToggleButton_Modify.setFocusable(false);
        jToggleButton_Modify.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jToggleButton_Modify.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToggleButton_Modify.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton_ModifyActionPerformed(evt);
            }
        });
        jToolBar1.add(jToggleButton_Modify);

        jButton_Delete.setText("Cancella");
        jButton_Delete.setFocusable(false);
        jButton_Delete.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton_Delete.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton_Delete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_DeleteActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton_Delete);

        jTable1.setModel(bankTableModel1);
        jTable1.setRowHeight(24);
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jTable1MouseReleased(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);
        jTable1.getColumnModel().getColumn(0).setHeaderValue("Banche");
        jTable1.getColumnModel().getColumn(0).setCellRenderer(bankTableRenderer1);

        jLabel_Message.setBackground(new java.awt.Color(204, 255, 204));
        jLabel_Message.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel_Message.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel_Message.setText("Inserimento Nuova Banca");
        jLabel_Message.setOpaque(true);

        jButton_Salva.setText("Salva");
        jButton_Salva.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_SalvaActionPerformed(evt);
            }
        });

        jButton_Annulla.setText("Annulla");
        jButton_Annulla.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_AnnullaActionPerformed(evt);
            }
        });

        jLabel13.setText("Nr. Iscrizione Albo Banche: ");

        jLabel7.setText("Indirizzo:");

        jLabel16.setText("Capitale Sociale:");

        jLabel4.setText("CAP:");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel2.setText("Sede Legale Istituto:");

        jCheckBox1.setText("seleziona se la sede corrisponde con la direzione");
        jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox1ActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel1.setText("Inserimento Anagrafica Istituto Banca");

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel6.setText("Direzione Generale Istituto:");

        jLabel3.setText("Indirizzo:");

        jLabel14.setText("ABI:");

        jLabel8.setText("CAP:");

        jLabel10.setText("Registro Imprese: ");

        jLabel5.setText("Città:");

        jLabel9.setText("Città:");

        jLabel15.setText("Gruppo Bancario:");

        jLabel12.setText("Partita Iva:");

        jLabel11.setText("Codice Fiscale:");

        jLabel17.setText("Attiva dal:");

        jLabel18.setText("al:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField_SLegale_Indirizzo))
                    .addComponent(jTextField_Denominazione)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addGap(24, 24, 24)
                        .addComponent(jTextField_SLegaleCAP, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField_SLegaleCity))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jCheckBox1, javax.swing.GroupLayout.DEFAULT_SIZE, 273, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField_SGenerale_Indirizzo))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addGap(24, 24, 24)
                        .addComponent(jTextField_SGeneraleCAP, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField_SGeneraleCity))
                    .addComponent(jSeparator1)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel10)
                            .addComponent(jLabel11)
                            .addComponent(jLabel12))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextField_PartitaIVA)
                            .addComponent(jTextField_CodiceFiscale)
                            .addComponent(jTextField_RegistroImprese)))
                    .addComponent(jSeparator2)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel13)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField_NrAlbo, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel14)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField_ABI))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel15)
                            .addComponent(jLabel16)
                            .addComponent(jLabel17))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextField_CapitaleSociale)
                            .addComponent(jTextField_GruppoBanca)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jDateChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel18)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jDateChooser2, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE)))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel18)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField_Denominazione, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel3)
                                    .addComponent(jTextField_SLegale_Indirizzo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel4)
                                    .addComponent(jTextField_SLegaleCAP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel5)
                                    .addComponent(jTextField_SLegaleCity, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(7, 7, 7)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel6)
                                    .addComponent(jCheckBox1))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel7)
                                    .addComponent(jTextField_SGenerale_Indirizzo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel8)
                                    .addComponent(jTextField_SGeneraleCAP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel9)
                                    .addComponent(jTextField_SGeneraleCity, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel10)
                                    .addComponent(jTextField_RegistroImprese, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel11)
                                    .addComponent(jTextField_CodiceFiscale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel12)
                                    .addComponent(jTextField_PartitaIVA, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel13)
                                    .addComponent(jTextField_NrAlbo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel14)
                                    .addComponent(jTextField_ABI, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel15)
                                    .addComponent(jTextField_GruppoBanca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel16)
                                    .addComponent(jTextField_CapitaleSociale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jDateChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel17)))
                            .addComponent(jDateChooser2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 278, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel_Message, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jButton_Annulla)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jButton_Salva, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap())
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 52, Short.MAX_VALUE)
                    .addComponent(jLabel_Message, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(40, 40, 40)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton_Salva)
                            .addComponent(jButton_Annulla)))
                    .addComponent(jScrollPane1))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton_SalvaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_SalvaActionPerformed
        String denominazione = this.jTextField_Denominazione.getText();
        String indirizzo_sedeLegale = this.jTextField_SLegale_Indirizzo.getText();
        String slegale_cap = jTextField_SLegaleCAP.getText();
        String slegale_city = jTextField_SLegaleCity.getText();
        String abi = jTextField_ABI.getText();
        String cf = jTextField_CodiceFiscale.getText();
        String nrAlbo = jTextField_NrAlbo.getText();
        String iva = jTextField_PartitaIVA.getText();
        String registroImprese = jTextField_RegistroImprese.getText();
        String sgenerale_cap = jTextField_SGeneraleCAP.getText();
        String sgenerale_city = jTextField_SGeneraleCity.getText();
        String sgenerale_address = jTextField_SGenerale_Indirizzo.getText();
        String gruppo = jTextField_GruppoBanca.getText();
        String capitale = jTextField_CapitaleSociale.getText();
        
        BankEWS_Service s = new BankEWS_Service();
        Bank bank = null;
        if (this.jToggleButton_NuovaBanca.isSelected()) {
            bank = new Bank();
        } else {
            bank = this.bankTableModel1.getSelectedBank(jTable1.getSelectedRow());
        }
        bank.setDenominazione(denominazione);
        bank.setSedeLegaleIndirizzo(indirizzo_sedeLegale);
        bank.setABI(abi);
        bank.setCF(cf);
        bank.setCapitaleSociale(capitale);
        bank.setGruppoBancario(gruppo);
        bank.setNumeroAlbo(nrAlbo);
        bank.setPartitaIVA(iva);
        bank.setRegistroImprese(registroImprese);
        bank.setSedeGeneraleCAP(sgenerale_cap);
        bank.setSedeGeneraleCity(sgenerale_city);
        bank.setSedeGeneraleIndirizzo(sgenerale_address);
        bank.setSedeLegaleCity(slegale_city);
        bank.setSedeLegaleCAP(slegale_cap);
        if (this.jToggleButton_NuovaBanca.isSelected()) {
            s.getBankEWSPort().create(bank);
            this.bankTableModel1.addRowElement(new BankItem(bank));
            JOptionPane.showMessageDialog(null, "Bank saved !");
            cancel();
        } else {
            s.getBankEWSPort().edit(bank);
            this.bankTableModel1.refreshByObjectField(bank);
            JOptionPane.showMessageDialog(null, "Bank updated !");
            cancel();
        }


    }//GEN-LAST:event_jButton_SalvaActionPerformed

    private void jToggleButton_NuovaBancaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton_NuovaBancaActionPerformed

        if (jToggleButton_NuovaBanca.isSelected()) {
            this.jToggleButton_Modify.setEnabled(false);
            this.jButton_Delete.setEnabled(false);
            this.jButton_Salva.setEnabled(true);
            this.jButton_Annulla.setEnabled(true);
            this.jLabel_Message.setText("- Inserimento Nuova Banca -");
            this.jLabel_Message.setBackground(ViewModeColor.INSERT.getColor());
            clearForm();
            setFormEnabled(true);
        } else {
            this.jToggleButton_Modify.setEnabled(true);
            this.jButton_Delete.setEnabled(true);
            this.jButton_Salva.setEnabled(false);
            this.jButton_Annulla.setEnabled(false);
            this.jLabel_Message.setText("");
            this.jLabel_Message.setBackground(null);
            setFormEnabled(false);
        }

    }//GEN-LAST:event_jToggleButton_NuovaBancaActionPerformed

    private void jTable1MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseReleased
        System.out.println("item selected");
        if (jTable1.getSelectedRow() != -1) {
            visualizeData(bankTableModel1.getSelectedBank(jTable1.getSelectedRow()));
            System.out.println("you have selected bank: " + this.bankTableModel1.getSelectedBank(jTable1.getSelectedRow()).getDenominazione());
        }
    }//GEN-LAST:event_jTable1MouseReleased

    private void jToggleButton_ModifyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton_ModifyActionPerformed
        int selectedRow = jTable1.getSelectedRow();
        if (selectedRow == -1) {
            JOptionPane.showMessageDialog(null, "Devi selezionare una banca", "Error", JOptionPane.ERROR_MESSAGE);
            this.jToggleButton_Modify.setSelected(false);
            return;
        }
        if (jToggleButton_Modify.isSelected()) {
            this.jLabel_Message.setText("- Modifica dati Banca -");
            this.jLabel_Message.setBackground(ViewModeColor.MODIFY.getColor());
            this.jToggleButton_NuovaBanca.setEnabled(false);
            this.jButton_Delete.setEnabled(false);
            this.jButton_Salva.setEnabled(true);
            this.jButton_Annulla.setEnabled(true);
            this.jLabel_Message.setText("- Inserimento Nuova Banca -");
            visualizeData(bankTableModel1.getSelectedBank(selectedRow));
            setFormEnabled(true);
        } else {
            cancel();
            visualizeData(bankTableModel1.getSelectedBank(selectedRow));
        }
    }//GEN-LAST:event_jToggleButton_ModifyActionPerformed

    private void jButton_AnnullaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_AnnullaActionPerformed
        cancel();
    }//GEN-LAST:event_jButton_AnnullaActionPerformed

    private void jButton_DeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_DeleteActionPerformed
        int selectedRow = jTable1.getSelectedRow();
        if (selectedRow == -1) {
            JOptionPane.showMessageDialog(null, "Devi selezionare una banca", "Error", JOptionPane.ERROR_MESSAGE);
            this.jToggleButton_Modify.setSelected(false);
            return;
        }
        int answer = JOptionPane.showConfirmDialog(null, "Vuoi veramente cancellare questa banca ?", "Messaggio", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
        if (answer == JOptionPane.YES_OPTION) {
            BankEWS_Service s = new BankEWS_Service();
            s.getBankEWSPort().remove(bankTableModel1.getSelectedBank(selectedRow));
            bankTableModel1.removeRowElement(selectedRow);
            JOptionPane.showMessageDialog(null, "Banca correttamente cancellata");
        } else {
            cancel();
        }
    }//GEN-LAST:event_jButton_DeleteActionPerformed

    private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
        if (jCheckBox1.isSelected()) {
            this.jTextField_SGenerale_Indirizzo.setText(this.jTextField_SLegale_Indirizzo.getText());
            this.jTextField_SGeneraleCAP.setText(this.jTextField_SLegaleCAP.getText());
            this.jTextField_SGeneraleCity.setText(this.jTextField_SLegaleCity.getText());
        } else {
            this.jTextField_SGenerale_Indirizzo.setText("");
            this.jTextField_SGeneraleCAP.setText("");
            this.jTextField_SGeneraleCity.setText("");
        }
    }//GEN-LAST:event_jCheckBox1ActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private ebasclient.gui.bank.item.BankTableModel bankTableModel1;
    private ebasclient.gui.bank.item.BankTableRenderer bankTableRenderer1;
    private javax.swing.JButton jButton_Annulla;
    private javax.swing.JButton jButton_Delete;
    private javax.swing.JButton jButton_Salva;
    private javax.swing.JCheckBox jCheckBox1;
    private com.toedter.calendar.JDateChooser jDateChooser1;
    private com.toedter.calendar.JDateChooser jDateChooser2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel jLabel_Message;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField_ABI;
    private javax.swing.JTextField jTextField_CapitaleSociale;
    private javax.swing.JTextField jTextField_CodiceFiscale;
    private javax.swing.JTextField jTextField_Denominazione;
    private javax.swing.JTextField jTextField_GruppoBanca;
    private javax.swing.JTextField jTextField_NrAlbo;
    private javax.swing.JTextField jTextField_PartitaIVA;
    private javax.swing.JTextField jTextField_RegistroImprese;
    private javax.swing.JTextField jTextField_SGeneraleCAP;
    private javax.swing.JTextField jTextField_SGeneraleCity;
    private javax.swing.JTextField jTextField_SGenerale_Indirizzo;
    private javax.swing.JTextField jTextField_SLegaleCAP;
    private javax.swing.JTextField jTextField_SLegaleCity;
    private javax.swing.JTextField jTextField_SLegale_Indirizzo;
    private javax.swing.JToggleButton jToggleButton_Modify;
    private javax.swing.JToggleButton jToggleButton_NuovaBanca;
    private javax.swing.JToolBar jToolBar1;
    // End of variables declaration//GEN-END:variables
}
